#include <bits/stdc++.h>
// 2025/02/06
// tag: 
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

#define int long long

int n, feel[100001], l[100001], r[100001], presum[100001];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> feel[i], presum[i] = presum[i - 1] + feel[i];
    stack<int> st;
    for (int i = 1; i <= n; i++){
        r[i] = n + 1;
        while (!st.empty() && feel[st.top()] > feel[i])
            r[st.top()] = i, st.pop();
        st.push(i);
    }
    st = stack<int>();
    for (int i = n; i >= 1; i--) {
        l[i] = 0;
        while (!st.empty() && feel[st.top()] > feel[i])
            l[st.top()] = i, st.pop();
        st.push(i);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans = max(ans, (presum[r[i] - 1] - presum[l[i]]) * feel[i]);
    cout << ans << endl;
    return 0;
}